<?php
session_start();
if(isset($_SESSION['admin_id'])) {
    include "../include/dbFunctions.php";
    include "../include/formFunctions.php";
    include "../include/menu.php";
    $id = $_SESSION['vid'];
    $mes="";
    if (isset($_SESSION['mes'])) {
        $mes = $_SESSION['mes'];
        $_SESSION['mes']="";
    }
// Data from volunteer table
    $query1 = "SELECT * FROM volunteer WHERE volunteer_id = $id";
    $volunteer_array = executeSelectQuery($query1);
    $salutation = $volunteer_array[0]['volunteer_salutation'];
    $surname = $volunteer_array[0]['volunteer_surname'];
    $firstname = $volunteer_array[0]['volunteer_firstname'];
    $gender = $volunteer_array[0]['volunteer_gender'];
    $office = $volunteer_array[0]['volunteer_office'];
    $mobile = $volunteer_array[0]['volunteer_mobile'];
    $sponsor_id = $volunteer_array[0]['sponsor_id'];
    $job = $volunteer_array[0]['volunteer_profession'];
    $exp = $volunteer_array[0]['volunteer_experience'];
    $ref = $volunteer_array[0]['volunteer_reference'];
    $cv = $volunteer_array[0]['volunteer_cv'];
    $comment = $volunteer_array[0]['volunteer_comment'];

// Data from sponsor table
    $query2 = "SELECT * FROM sponsor";
    $sponsor_array = executeSelectQuery($query2);
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>JA Scheduling</title>

        <script type="text/javascript" language="javascript" src="../media/js/jquery/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" language="javascript" src="../media/js/jquery/dataTable.js"></script>
        <script type="text/javascript" language="javascript" src="../media/js/jquery/jquery.validate.js"></script>
        <script type="text/javascript" language="javascript" src="../media/js/volunteerValidation.js"></script>

        <!--  CSS script -->
        <link rel="stylesheet" href="../media/css/screen.css" type="text/css" media="screen" title="default" />
        <link type="text/css" href="../media/css/dataTable.css" rel="stylesheet" />

        <!-- Manage table script -->
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                $('#admintable').dataTable( {
                    "sPaginationType": "full_numbers"
                } );
                $("#volunteerform").validate(options_validate);
            } );
        </script>

    </head>
    <body>
        <!-- DON'T TOUCH! Start: page-top-outer -->
            <?php
            top_outer();
            ?>
        <!-- End: page-top-outer -->

        <div class="clear">&nbsp;</div>

        <!--  start nav-outer-repeat................................................................................................. START -->
        <div class="nav-outer-repeat">
            <!--  start nav-outer -->
            <div class="nav-outer">

                <!-- start nav-right -->
                    <?php
                    nav_right();
                    ?>
                <!-- end nav-right -->
                <!--  start nav -->
                <div class="nav">
                    <div class="table">
                            <?php
                            navigation_volunteer();
                            ?>
                        <div class="clear"></div>
                    </div>
                    <div class="clear"></div>
                </div>
                <!--  start nav -->

            </div>
            <div class="clear"></div>
            <!--  start nav-outer -->
        </div>
        <!--  start nav-outer-repeat................................................... END -->

        <div class="clear"></div>

        <!-- start content-outer ........................................................................................................................START -->
        <div id="content-outer">
            <!-- start content -->
            <div id="content">

                <!--  start page-heading --> <!--lyedit-->
                <div id="page-heading">
                    <h1>Edit Volunteer</h1>
                </div>
                <!-- end page-heading -->

                <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table" >
                    <tr>
                        <th rowspan="3" class="sized"><img src="../media/images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
                        <th class="topleft"></th>
                        <td id="tbl-border-top">&nbsp;</td>
                        <th class="topright"></th>
                        <th rowspan="3" class="sized"><img src="../media/images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
                    </tr>
                    <tr>
                        <td id="tbl-border-left"></td>
                        <td>
                            <!--  start content-table-inner ...................................................................... START -->
                            <div id="content-table-inner">
                                <div id="table-content">
                                    <b><font color = 'red'><?php echo $mes; ?></font></b><br/>
                                    <em>* Required fields</em><br/>
                                    <h3>Personal Information</h3>
                                    <form enctype="multipart/form-data" action="action/volunteerDoUpdateGeneral.php" method="post" id="volunteerform">

                                        <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                            <input type="hidden" name="id" value=<?php echo $id;?>></input>
                                            <tr>
                                                <th valign="top">Salutation:  <em>*</em> </th>
                                                <td>
                                                    <select class="styledselect_form_1"  name="salutation">
                                                            <?php
                                                            $value_array = Array('Mr.','Ms.','Mrs.','Dr.');
                                                            $display_array = Array('Mr.','Ms.','Mrs.','Dr.');
                                                            dynamicSelectForm($salutation,$value_array,$display_array);
                                                            ?>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr></tr>
                                            <tr>
                                                <th valign="top">Given Name: <em>*</em> </th>
                                                <td><input class="inp-form" type="text" name="firstname" value='<?php echo $firstname ; ?>'></input></td>
                                            </tr>
                                            <tr>
                                                <th valign="top">Family Name: <em>*</em> </th>
                                                <td><input class="inp-form" type="text" name="surname" value='<?php echo $surname ; ?>'></input></td>
                                            </tr>
                                            <tr>
                                                <th valign="top">Gender:<em>*</em> </th>
                                                <td>
                                                    <select class="styledselect_form_1"  name="gender">
                                                            <?php
                                                            $value_array = Array('male','female');
                                                            $display_array = Array('Male','Female');
                                                            dynamicSelectForm($gender,$value_array,$display_array);
                                                            ?>
                                                    </select><br/>
                                                </td>
                                            </tr>

                                            <tr>
                                                <th valign="top">Office Phone:</th>
                                                <td><input class="inp-form" type="text" name="office" value=<?php echo $office ; ?>></input></td>
                                            </tr>
                                            <tr>
                                                <th valign="top">Mobile Phone:<em>*</em> </th>
                                                <td><input class="inp-form" type="text" name="mobile" value=<?php echo $mobile ; ?>><br/></input><br/></td>
                                            </tr>
                                            <tr>
                                                <th valign="top">Organization:<em>*</em> </th>
                                                <td>
                                                    <select class="styledselect_form_1"  name="sponsor">
                                                            <?php
                                                            $value_array = getValueArray($sponsor_array,"sponsor_id");
                                                            $display_array = getValueArray($sponsor_array,"sponsor_name");
                                                            dynamicSelectForm($sponsor_id,$value_array,$display_array);
                                                            ?>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <th valign="top">Profession: <em>*</em> </th>
                                                <td><input class="inp-form" type="text" name="job" value='<?php echo $job ; ?>'></input></td>
                                            </tr>
                                            <tr>
                                                <th valign="top">Experience:<em>*</em>  </th>
                                                <td><textarea class="form-textarea"  name="exp" ><?php echo $exp ; ?></textarea></td>
                                            </tr>
                                            <tr>
                                                <th valign="top">Reference: <em>*</em> </th>
                                                <td><textarea class="form-textarea"  name="ref" ><?php echo $ref ; ?></textarea></td>
                                            </tr>

                                                <?php
                                                if ($cv!=null) {
                                                    echo <<<HERE
                                                        <tr><th valign="top">Resumé: </th>
                                                    <td><a href = '../upload/cv/$cv'>$cv</a><a onclick="return  confirm('This file will be permanently deleted. Do you wish to continue?')" href='action/volunteerDeleteCV.php?file=$cv'>  <img src='../media/images/forms/delete-icon.png' height ='12'></a></td></tr>
HERE;
                                                }
                                                if ($cv==null) {
                                                    echo <<<HERE
                                                        <tr><th valign="top">Resumé: </th>
                                                    <td><input name="uploaded_file" type="file" /></td></tr>
HERE;
                                                }
                                                ?>
                                            <tr>
                                                <th valign="top">Comment: <em>*</em> </th>
                                                <td><textarea class="form-textarea"  name="comment" ><?php echo $comment ; ?></textarea></td>
                                            </tr>
                                        </table>
                                        <br/>
                                        <input type="button" value="&nbsp" class="form-back" onClick="javascript:history.go(-1)"/>
                                        <input type="submit" value="&nbsp" class="form-save" />
                                        <input type="reset" value="&nbsp" class="form-reset"  />

                                    </form>
                                </div>
                                <h2></h2>
                                <!--  start table-content  --> <!--lyedit-->
                                <div id="table-content">
                                    <!--  Can put table start from here within this div--> <!--lyedit-->

                                    <!--  end table-content here -->
                                </div>
                                <div class="clear"></div>
                            </div>
                            <!--  end content-table-inner ............................................END  -->
                        </td>
                        <td id="tbl-border-right"></td>
                    </tr>
                    <tr>
                        <th class="sized bottomleft"></th>
                        <td id="tbl-border-bottom">&nbsp;</td>
                        <th class="sized bottomright"></th>
                    </tr>
                </table>
                <div class="clear">&nbsp;</div>

            </div>
            <!--  end content -->
            <div class="clear">&nbsp;</div>
        </div>
        <!--  end content-outer........................................................END -->
            <?php
            footer();
            ?>

    </body>
</html>
    <?php
}else {
    header("Location: ../include/login.html");
}
?>